package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.List; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblCTDTKhoiNganhMonHoc;
import com.lb.jwitter.service.TblCTDTKhoiNganhMonHocService;
import com.lb.jwitter.service.TblCTDTKhoiNganh;
import com.lb.jwitter.service.TblCTDTKhoiNganhService;

import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblCTDTKhoiNganhtblCTDTKhoiNganhMonHocUpdateAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private int khoiNganhId; 
    public void setKhoiNganhId(int khoiNganhId) {
       this.khoiNganhId = khoiNganhId;
 }

    public int getKhoiNganhId() {
       return khoiNganhId;
 }

    private TblCTDTKhoiNganhService tblCTDTKhoiNganhService; 

    private int monHocId; 
    public void setMonHocId(int monHocId) {
       this.monHocId = monHocId;
 }

    public int getMonHocId() {
       return monHocId;
 }

    private TblCTDTMonHocService tblCTDTMonHocService; 

    private String hocKy; 
    public void setHocKy(String hocKy) {
       this.hocKy = hocKy;
 }

    public String getHocKy() {
       return hocKy;
 }

    private int sTT; 
    public void setSTT(int sTT) {
       this.sTT = sTT;
 }

    public int getSTT() {
       return sTT;
 }

    private String maLoaiBB; 
    public void setMaLoaiBB(String maLoaiBB) {
       this.maLoaiBB = maLoaiBB;
 }

    public String getMaLoaiBB() {
       return maLoaiBB;
 }

    private String ghiChu; 
    public void setGhiChu(String ghiChu) {
       this.ghiChu = ghiChu;
 }

    public String getGhiChu() {
       return ghiChu;
 }

    private TblCTDTKhoiNganhMonHoc tblCTDTKhoiNganhMonHoc; 
    public void setTblCTDTKhoiNganhMonHoc (TblCTDTKhoiNganhMonHoc tblCTDTKhoiNganhMonHoc) {
        this.tblCTDTKhoiNganhMonHoc = tblCTDTKhoiNganhMonHoc;
 }

    private TblCTDTKhoiNganhMonHocService tblCTDTKhoiNganhMonHocService; 

    private List<TblCTDTKhoiNganhMonHoc> tblCTDTKhoiNganhMonHocs; 
    public List<TblCTDTKhoiNganhMonHoc>  getTblCTDTKhoiNganhMonHocs() {
        return tblCTDTKhoiNganhMonHocs; 
      } 

	private int preUpdate(Message msg, TblCTDTKhoiNganhMonHoc obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblCTDTKhoiNganhMonHoc obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_CTDT_KhoiNganh_MonHoc", "sua")){ 
        return "noprivilege"; 
    }
        tblCTDTKhoiNganhMonHocService = (TblCTDTKhoiNganhMonHocService) context.getBean("tbl_CTDT_KhoiNganh_MonHocClient"); 
        tblCTDTKhoiNganhService = (TblCTDTKhoiNganhService) context.getBean("tbl_CTDT_KhoiNganhClient"); 

        tblCTDTMonHocService = (TblCTDTMonHocService) context.getBean("tbl_CTDT_MonHocClient"); 

        msg = new Message(); 
        tblCTDTKhoiNganhMonHoc = tblCTDTKhoiNganhMonHocService.gettblCTDTKhoiNganhMonHoc(new Long(id)); 
        tblCTDTKhoiNganhMonHoc.setKhoiNganhId(tblCTDTKhoiNganhService.gettblCTDTKhoiNganh(new Long(khoiNganhId))); 
        tblCTDTKhoiNganhMonHoc.setMonHocId(tblCTDTMonHocService.gettblCTDTMonHoc(new Long(monHocId))); 
        tblCTDTKhoiNganhMonHoc.setHocKy(hocKy); 
        tblCTDTKhoiNganhMonHoc.setSTT(sTT); 
        tblCTDTKhoiNganhMonHoc.setMaLoaiBB(maLoaiBB); 
        tblCTDTKhoiNganhMonHoc.setGhiChu(ghiChu); 
        preUpdate(msg,tblCTDTKhoiNganhMonHoc); 
       if (msg.isPreMessage_b()) 
       { 
           tblCTDTKhoiNganhMonHocService.updatetblCTDTKhoiNganhMonHoc(tblCTDTKhoiNganhMonHoc); 
           postUpdate(msg, tblCTDTKhoiNganhMonHoc); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

       if(pageSize == 0){ 
           pageSize = 20; 
       } 
        if(page == 0){ 
           page =1; 
       } 
        List < ConditionReport > cons = new ArrayList<ConditionReport>(); 
       ConditionReport con = new ConditionReport(); 
        con.setCol("khoiNganhId.id"); 
        con.setValue1(new Long(khoiNganhId)); 
        con.setOperator("eq"); 
        cons.add(con); 
      tblCTDTKhoiNganhMonHocs =       tblCTDTKhoiNganhMonHocService.findtblCTDTKhoiNganhMonHocByCondition(cons,pageSize, page); 
      pages = tblCTDTKhoiNganhMonHocService.counttblCTDTKhoiNganhMonHocByCondition(cons)/pageSize + 1; 
      dataString = ""; 
      dataString += "&id="; 
      dataString += "&khoiNganhId="; 
      dataString += "&monHocId="; 
      dataString += "&hocKy="; 
      dataString += "&sTT="; 
      dataString += "&maLoaiBB="; 
      dataString += "&ghiChu="; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_CTDT_KhoiNganh_MonHoc Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
